package ACM_Brush;

import java.util.Scanner;

public class Solution1143 {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            String text1 = in.nextLine();
            String text2 = in.nextLine();
            System.out.println();
            System.out.println(new solution_1143().longestSequence(text1, text2));
        }
    }
}

class solution_1143 {
    public int longestSequence(String text1, String text2) {
        int length1 = text1.length();
        int length2 = text2.length();

        // s[0~i] 和 t[0~j] 的最长子序列
        int[][] dp = new int[length1 + 1][length2 + 1];

        for (int i = 1; i <= length1; i++) {
            for (int j = 1; j <= length2; j++) {
                if (text1.charAt(i - 1) == text2.charAt(j - 1))
                    dp[i][j] = Math.max(Math.max(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1] + 1);
                else
                    dp[i][j] = Math.max(Math.max(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]);
            }
        }

        return dp[length1][length2];
    }
}